package com.Smart.smartscals.CustomView;

import java.util.ArrayList;

import com.Smart.smartscals.Utils.Tools;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff.Mode;
import android.util.AttributeSet;
import android.view.View;

public class CustomDrawReportView extends View {
	private Paint mPaint;
	private Canvas mCanvas;
	private int mWith, mHeight;
	private int onePiceX;
	private final int aliBottom =40;
	private ArrayList<String> drawTextArrayList;

	public CustomDrawReportView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void statTration(ArrayList<String> drawTextArrayList) {
		this.drawTextArrayList = drawTextArrayList;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		
		clear(canvas);
		getHeightWidth();
		initParam(canvas);
		drawLine();
		drawTimeTv();

	}

	public void clear(Canvas canvas) {
		Paint paint = new Paint();
		paint.setXfermode(new PorterDuffXfermode(Mode.DST));
		canvas.drawPaint(paint);
	}
	private void drawTimeTv() {
		if (drawTextArrayList == null || drawTextArrayList.size() == 0)
			return;
		mPaint.setTextSize(25);
		for (int i = 0; i < drawTextArrayList.size(); i++) {
			mCanvas.drawText(drawTextArrayList.get(i), onePiceX * (i + 1) - 5,
					mHeight-5 , mPaint);
		}

	}

	private void drawLine() {

		for (int i = 0; i < 7; i++) {// 画竖线；
			mCanvas.drawLine(onePiceX * (i + 1), 0, onePiceX * (i + 1), mHeight
					- aliBottom, mPaint);
		}
		mCanvas.drawLine(onePiceX, mHeight - aliBottom, 7 * onePiceX, mHeight
				- aliBottom, mPaint);

	}

	private void initParam(Canvas canvas) {
			mCanvas = canvas;
		if (mPaint == null) {
			mPaint = new Paint();
			mPaint.setColor(Color.WHITE);

			onePiceX = mWith / 8;// 总共8份；
		}

	}

	private void getHeightWidth() {
	
		if (mHeight == 0) {
			mHeight = this.getHeight();
			mWith = this.getWidth();
		}
		Tools.setLog("---->getHeitht:getHeightWidth:"+mHeight+"  "+this.getHeight());
	}

}
